#ifndef LineEditShell_h
#define LineEditShell_h

#include "../ShellBase.h"
#include "../../XXqtDefine.h"
#include <QLineEdit>
#include <QRegExp>
#include <QSharedPointer>

class LineEditShell : public ShellBase
{
	Q_OBJECT
public:
    LineEditShell(QObject *parent = nullptr);

    void shell(QLineEdit *lineEdit);

	/**
     inputExpression: fix to input, can not input when not matching;
     matchExpression: fix to result;
	 */
	virtual void config(const QVariant &param);
    void configExpression(const QString &input, const QString &match);
    void configInputExpression(const QString &expression);
    void configMatchExpression(const QString &expression);

    virtual QVariant action(const QString &name, const QVariant &info=QVariant());
    bool isMatching() const { return _isMatching;}

    /** param */
    XX_KEY(kInputExpression)
    XX_KEY(kMatchExpression)

    /** action */
    XX_KEY(kIsMatching)

    /** event */
    XX_KEY(kSigTextChanged)
    XX_KEY(kPreviousText)
    XX_KEY(kCurrentText)

protected:
    virtual void installTarget(const QString &name, QObject *target);
    virtual void uninstallTarget(const QString &name, QObject *target);
    virtual void textDidChanged(const QString &previous, const QString &current){}

    Q_SLOT void onTextEdited(QString text);
    Q_SLOT void onTextChanged(QString text);

private:
    bool input(const QString &text);
    bool match(const QString &text);

private:
    QSharedPointer<QRegExp> _inputExpression;
    QSharedPointer<QRegExp> _matchExpression;
    bool _isMatching;
    QString _currentText;
};
#endif // !LineEditShell_h
